package drive.Controller;

import drive.Model.Article;
import drive.Service.ServiceInterface.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//已完成本控制器测试，2025.3.17
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    // 查询所有文章
    @GetMapping()
    public String selectAllArticles() {
        return articleService.findAll();
    }

    // 根据查询ID文章
    @GetMapping("/{articleId}")
    public String selectArticleById(@PathVariable("articleId") int articleId) {
        return articleService.findById(articleId);
    }

    // 新增文章
    @PostMapping()
    public String addArticle(@RequestBody Article article) {
        return articleService.add(article);
    }

    // 更新文章
    @PutMapping()
    public String updateArticle(@RequestBody Article article) {
        return articleService.update(article);
    }

    // 删除文章
    @DeleteMapping("/{articleId}")
    public String deleteArticle(@PathVariable("articleId") int articleId) {
        return articleService.delete(articleId);
    }
}
